package com.hy.controller.check;

import com.hy.common.base.RespResult;
import com.hy.common.log.annotation.SysOpLogAnnotation;
import com.hy.entity.dto.*;
import com.hy.service.HyCheckService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/check")
public class CheckController {



    @Resource
    private HyCheckService checkService;
    @PostMapping("/sortByDto")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "选择盘点单分类",reqParam = "T(com.hy.common.utils.StateUtil).getSortMode(#checkSortDTO.sortMode)")
    public RespResult  sortByDto(@RequestBody CheckSortDTO checkSortDTO){


        return checkService.sortByDTO(checkSortDTO);

    }
    @PostMapping("/add")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "新增盘点单",reqParam = "#addDTO.hyCheck")
    public RespResult add(@RequestBody CheckAddDTO addDTO){
        return checkService.addHyCheck(addDTO);
    }


    @GetMapping("/showCheckList")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "查看盘点单",reqParam = "#searchDTO")
    public RespResult showCheckList(CheckSearchDTO searchDTO){
        return checkService.searchByDTO(searchDTO);


    }
    @GetMapping("/getCheckTaskById")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "查看我的盘点任务",reqParam = "#userId")

    public RespResult getCheckTaskById(Integer userId){


        return checkService.getCheckTaskById(userId);


    }
    @GetMapping("/getDetailByTaskDto")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "查看盘点详情",reqParam = "'无'")
    public RespResult getDetailByTaskId(TaskDetailDTO taskDetailDTO){

        return checkService.getDetailByTaskDetailDto(taskDetailDTO);


    }
    @PostMapping("/updateState")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "审核盘点单、盘点任务",reqParam = "T(com.hy.common.utils.ELUtil).getParse(#checkDTO)")
    public RespResult updateState(CheckDTO checkDTO){

        return checkService.checkState(checkDTO);


    }
    @PostMapping("/overTask")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "提交审核盘点任务",reqParam = "#checkTaskId")

    public RespResult overTask(Integer checkTaskId){
            return checkService.overTask(checkTaskId);
    }

    @PostMapping("/checkByDto")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "手持机成功盘点",reqParam = "'盘点信息'")
    public RespResult checkById(CheckDetailDTO detailDTO){


        return checkService.checkOneByDto(detailDTO);

    }

    /**
     * 提供手持机 、按照房间的形式查看我需要盘点的所有资产接口。
     * @return
     */
    @RequestMapping("/getTaskPlaceTree")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "按照房间展示盘点详情",reqParam = "#checkTaskId")
    public RespResult getTask(Integer checkTaskId){

        return checkService.getTaskPlace(checkTaskId);


    }
    @RequestMapping("/getPropertyByEpc")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "通过epc查询资产",reqParam = "'epc:'+#epc")
    public RespResult getPropertyByEpc(String epc){

        return checkService.getPropertyByEpc(epc);


    }
    @RequestMapping("/checkTab")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "查看盘点单tab页",reqParam = "'查看盘点tab'")
    public RespResult checkTab(Integer checkId){

        return checkService.getCheckTab(checkId);
    }
    @PostMapping("/errorPro")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "上报异常",reqParam = "'上报异常任务'")
    public RespResult errorPro(@RequestBody ErrorProAddDTO addDTO){

        return checkService.addErrorPro(addDTO);
    }
    @PostMapping("/upPhoto")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "上传图片",reqParam = "'拍照上传异常资产图片'")
    public RespResult upPhoto(@RequestParam("file") MultipartFile multipartFile, HttpServletRequest request){

        return checkService.uploadPhoto(multipartFile,request);
    }
    @PostMapping("/updateError")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "更改异常申报状态",reqParam = "T(com.hy.common.utils.ELUtil).getErrorRecordParse(#upDateDTO)")
    public RespResult updateError(@RequestBody ErrorUpDateDTO upDateDTO){

        return checkService.updateError(upDateDTO);
    }
    @PostMapping("/errorShow")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "查询异常申报历史",reqParam = "'查询历史异常申报列表'")
    public RespResult errorShow(@RequestBody ErrorQueryDTO queryDTO){

        return checkService.queryByDTO(queryDTO);
    }
    @GetMapping("/waitError")
    @SysOpLogAnnotation(menuName = "盘点",menuBtn = "查询待处理异常列表",reqParam = "'查询待处理异常列表'")
    public RespResult waitError(ErrorQueryDTO queryDTO){

        return checkService.queryWaitErrorByDTO( queryDTO);
    }



}
